var t = require("../../../@babel/runtime/helpers/defineProperty"), a = getApp(), e = require("../../../mybehaviors/location/location");

Page({
    behaviors: [ e ],
    data: {
        msgText: 0,
        showtips: !0,
        swlist: [],
        swlis: [],
        shenqShow: !1,
        is_hotel: !1,
        uploadUrl: "",
        o2o_status: 1,
        address: "",
        point: {
            lat: "",
            lng: ""
        },
        city: "",
        title: "",
        noIs: !0,
        bor: !0,
        showDel: !1,
        apply: {
            password: "",
            realname: "",
            mobile: "",
            deliver_name: "",
            lng: "",
            lat: "",
            business_hours_start: "00:00",
            business_hours_end: "00:00",
            province_id: "",
            city_id: "",
            district_id: "",
            street_id: "",
            address: "",
            aptitute: [],
            remark: "",
            id_card_front: "",
            id_card_side: ""
        },
        categoryName: "",
        strShow: !1,
        provinceData: [],
        cityData: [],
        districtData: [],
        pickerValue: [ 0, 0, 0 ],
        selectAddressData: [],
        districtVal: [],
        streetShow: !1,
        addressShow: !1,
        addressName: "",
        provice: "",
        beginTimeshow: !1,
        endTimeshow: !1,
        imageUrl: "",
        hotelTitleType: "",
        levelShow: !1,
        applyOptionInfo: {},
        apply_switch: !1
    },
    onLoad: function(t) {
        var a, e, s = this;
        this.initData(), wx.setNavigationBarTitle({
            title: "申请"
        }), this.setData({
            uploadUrl: "upload.uploadPic"
        }), this._initAddressInfo(), this.getData();
        try {
            var i = wx.getStorageSync("ztd_temporary") || null;
            i && this.setData({
                apply: i
            });
        } catch (t) {
            console.log(t);
        }
        this._getLocation(function(t, a) {
            s.setData({
                "apply.lng": a.lng,
                "apply.lat": a.lat,
                mapdata_address: t.address
            });
        });
        var o = wx.getStorageSync("yz_basic_info");
        this.setData({
            apply_switch: null !== (a = null === (e = o.plugin_setting.sub_platform) || void 0 === e ? void 0 : e.apply_switch) && void 0 !== a && a
        });
    },
    goloc: function() {
        wx.setStorageSync("ztd_temporary", this.data.apply), wx.navigateTo({
            url: "/packageC/o2o/o2oLocation_loc/o2oLocation_loc?tag=selfCarryApply"
        });
    },
    showdel: function(t) {
        console.log(t), this.setData({
            showDel: !0
        });
    },
    delIntu: function(t) {
        var a = this.data.showpaths;
        this.setData({
            showpaths: a
        });
    },
    delIntu_2: function(t) {
        var a = this.data.showpaths_two;
        this.setData({
            showpaths_two: a
        });
    },
    shenqShow: function() {
        this.setData({
            shenqShow: !0
        });
    },
    onClicksQ: function() {
        this.setData({
            shenqShow: !1
        });
    },
    callKf: function() {
        console.log("联系客服");
    },
    onReady: function() {},
    onShow: function() {
        try {
            var t = wx.getStorageSync("applyaddresspoint");
            t && this.setData({
                "apply.lng": t.point.lng,
                "apply.lat": t.point.lat,
                mapdata_address: t.address
            });
        } catch (t) {
            console.log(t);
        }
    },
    onHide: function() {},
    onUnload: function() {},
    onPullDownRefresh: function() {},
    onReachBottom: function() {},
    onShareAppMessage: function() {},
    initData: function() {
        this.setData({
            showtips: !0,
            msgText: 0,
            o2o_status: 1,
            "apply.username": "",
            "apply.password": "",
            "apply.realname": "",
            "apply.mobile": "",
            "apply.deliver_name": "",
            "apply.lng": "",
            "apply.lat": "",
            "apply.province_id": "",
            "apply.city_id": "",
            "apply.district_id": "",
            "apply.street_id": "",
            "apply.aptitute": [],
            "apply.remark": "",
            agreementChoose: !1
        });
    },
    getData: function() {
        var t = this, e = "";
        e += a.getNetAddresss("plugin.package-deliver.frontend.apply.verify"), a._getNetWork({
            url: e,
            success: function(e) {
                var s = e.data;
                1 == s.result ? (t.setData({
                    o2o_status: 1,
                    applyOptionInfo: s.data
                }), wx.setNavigationBarTitle({
                    title: s.data.name + "申请"
                }), a._isTextEmpty(s.data.cservice) ? t.setData({
                    cservice: !1
                }) : t.setData({
                    cservice: !0
                })) : (t.setData({
                    o2o_status: 2
                }), wx.showToast({
                    icon: "none",
                    title: s.msg,
                    duration: 1500
                }));
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    usernameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.username": a
        });
    },
    passwordinp: function(t) {
        var a = t.detail;
        this.setData({
            "apply.password": a
        }), this.msgText = this.checkStrong(a), 3 == this.msgText ? this.setData({
            showtips: !1
        }) : this.setData({
            showtips: !0
        });
    },
    checkStrong: function(t) {
        var a = 0;
        if (t.length < 1) return a;
        switch (/\d/.test(t) && a++, /[a-z]/.test(t) && a++, /[A-Z]/.test(t) && a++, a) {
          case 1:
            return 1;

          case 2:
            return 2;

          case 3:
            return t.length < 8 ? 2 : 3;
        }
        return a;
    },
    realnameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.realname": a
        });
    },
    mobileinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.mobile": a
        });
    },
    storeNameinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.deliver_name": a
        });
    },
    showCategory: function() {
        this.setData({
            categoryShow: !0
        });
    },
    onClickLeft: function() {
        this.setData({
            categoryShow: !1
        });
    },
    chooseCategory: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            categoryName: a.name,
            "apply.categoryId": a.id,
            categoryShow: !1
        });
    },
    addressShowbtn: function() {
        this.setData({
            addressShow: !0
        });
    },
    showAddBtn: function(a) {
        var e = a.currentTarget.dataset.idex;
        this.setData(t({}, "diydata[" + e + "].showAdd", !0));
    },
    _closeDateLw: function() {
        this.setData({
            addressShow: !1
        });
    },
    _initAddressInfo: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("地址信息准备就绪"), t._getProvinceData();
            },
            fail: function(e) {
                console.log("省fail"), a._getNetWork({
                    url: a.getNetAddresss("member.member-address.address"),
                    success: function(a) {
                        var e = a.data, s = e.data.province, i = e.data.city, o = e.data.district;
                        wx.setStorage({
                            key: "provinceData",
                            data: s
                        }), wx.setStorage({
                            key: "cityData",
                            data: i
                        }), wx.setStorage({
                            key: "districtData",
                            data: o
                        }), t._initAddressInfo();
                    },
                    fail: function(t) {},
                    state: !0
                });
            }
        });
    },
    _getProvinceData: function() {
        var t = this;
        wx.getStorage({
            key: "provinceData",
            success: function(a) {
                console.log("省读取成功", a.data), t.setData({
                    provinceData: a.data
                }), t.setData({
                    "selectAddressData[0].name": a.data[t.data.pickerValue[0]].areaname,
                    "selectAddressData[0].id": a.data[t.data.pickerValue[0]].id,
                    "selectAddressData[0].index": t.data.pickerValue[0]
                }), t._getCityData();
            }
        });
    },
    _getCityData: function() {
        var t = this.data.selectAddressData[0];
        console.log("城市", "_data", t);
        var a = this;
        wx.getStorage({
            key: "cityData",
            success: function(e) {
                console.log("城市读取成功", e);
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("城市数据筛选", s), a.setData({
                    cityData: s
                }), a.setData({
                    "selectAddressData[1].name": s[a.data.pickerValue[1]].areaname,
                    "selectAddressData[1].id": s[a.data.pickerValue[1]].id,
                    "selectAddressData[1].index": a.data.pickerValue[1]
                }), a._getDistrictData();
            }
        });
    },
    _getDistrictData: function() {
        var t = this.data.selectAddressData[1];
        console.log("地区", "_data", t), console.log(t);
        var a = this;
        wx.getStorage({
            key: "districtData",
            success: function(e) {
                console.log("地区读取成功");
                for (var s = [], i = 0; i < e.data.length; i++) e.data[i].parentid == t.id && s.push(e.data[i]);
                console.log("地区数据筛选", s), a.setData({
                    districtData: s
                }), console.log("districtData", s), a.setData({
                    "selectAddressData[2].name": s[a.data.pickerValue[2]].areaname,
                    "selectAddressData[2].id": s[a.data.pickerValue[2]].id,
                    "selectAddressData[2].index": a.data.pickerValue[2]
                }), console.log("over", a.data.selectAddressData);
            }
        });
    },
    bindChange: function(t) {
        var a = t.detail.value;
        this.data.pickerValue[0] != a[0] && (a[1] = 0, a[2] = 0), this.data.pickerValue[1] != a[1] && (a[2] = 0), 
        this.setData({
            "pickerValue[0]": a[0],
            "pickerValue[1]": a[1],
            "pickerValue[2]": a[2]
        }), this._initAddressInfo();
    },
    resultAdd: function() {
        var t = this.data.selectAddressData, a = t[0].name + " " + t[1].name + " " + t[2].name;
        this.setData({
            addressName: a,
            provice: t[0].name,
            city: t[1].name,
            district: t[2].name
        }), this.setData({
            "apply.province_id": t[0].id,
            "apply.city_id": t[1].id,
            "apply.district_id": t[2].id,
            addressShow: !1
        }), this.getStreet(t[2].id);
    },
    getStreet: function(t) {
        var e = this, s = "";
        s += a.getNetAddresss("member.memberAddress.street"), s += "&district_id=" + t, 
        a._getNetWork({
            url: s,
            success: function(t) {
                var s = t.data;
                1 == s.result && !a._isTextEmpty(s.data) && s.data.length > 0 ? e.setData({
                    districtVal: s.data,
                    strShow: !0
                }) : e.setData({
                    strShow: !1
                });
            },
            fail: function(t) {
                console.log(t);
            }
        });
    },
    streetShowbtn: function() {
        this.setData({
            streetShow: !0
        });
    },
    treetShowLeft: function() {
        this.setData({
            streetShow: !1
        });
    },
    streetConfirm: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            street: a.areaname,
            "apply.street_id": a.id,
            streetShow: !1
        });
    },
    addressinp: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.address": a
        });
    },
    endTimebtn: function() {
        this.setData({
            endTimeshow: !0
        });
    },
    endTimeClose: function() {
        this.setData({
            endTimeshow: !1
        });
    },
    beginTimemessage: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.business_hours_start": a
        });
    },
    endTimemessage: function(t) {
        var a = t.detail.value;
        this.setData({
            "apply.business_hours_end": a
        });
    },
    onRead_6: function() {
        var t = this;
        wx.chooseImage({
            count: 9,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                t.unload({
                    tempFilePaths: a.tempFilePaths
                }, "2");
            }
        });
    },
    unload: function(t, e) {
        console.log(e);
        var s = a.getNetAddresss(this.data.uploadUrl), i = this, o = t.i ? t.i : 0, n = t.success ? t.success : 0, l = t.fail ? t.fail : 0;
        wx.uploadFile({
            url: s,
            filePath: t.tempFilePaths[o],
            name: "file",
            formData: null,
            success: function(t) {
                var a = JSON.parse(t.data);
                console.log(a.data.img_url), i.data.swlis.push(a.data.img_url), i.setData({
                    showpaths_two: i.data.swlis,
                    "apply.thumb": i.data.swlis
                }), console.log(i.data.apply);
            },
            fail: function(t) {
                l++;
            },
            complete: function(a) {
                ++o == t.tempFilePaths.length ? (console.log("执行完毕"), console.log("成功：" + n + " 失败：" + l)) : (t.i = o, 
                t.success = n, t.fail = l, i.unload(t, e));
            }
        });
    },
    onRead_3: function() {
        var t = this, e = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var s = a.tempFilePaths;
                console.log(s[0]);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        1 == e.result ? t.setData({
                            fileList3: e.data.img_url,
                            "apply.aptitute": [ e.data.img_url ]
                        }) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_4: function() {
        var t = this, e = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var s = a.tempFilePaths;
                console.log(s[0]);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        1 == e.result ? (t.setData({
                            fileList4: i,
                            "apply.id_card_front": e.data.img_url
                        }), console.log(t.data.apply.id_card_front)) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    onRead_5: function() {
        var t = this, e = a.getNetAddresss(this.data.uploadUrl);
        wx.chooseImage({
            count: 1,
            sizeType: [ "original", "compressed" ],
            sourceType: [ "album", "camera" ],
            success: function(a) {
                var s = a.tempFilePaths;
                console.log(s[0]);
                var i = s[0];
                wx.uploadFile({
                    url: e,
                    filePath: i,
                    name: "file",
                    success: function(a) {
                        var e = JSON.parse(a.data);
                        1 == e.result ? (t.setData({
                            fileList5: e.data.img_url,
                            "apply.id_card_side": e.data.img_url
                        }), console.log(t.data.apply)) : wx.showToast({
                            icon: "none",
                            title: e.msg,
                            duration: 1500
                        });
                    }
                });
            }
        });
    },
    remarkinp: function(t) {
        var a = t.detail.value;
        console.log(a), this.setData({
            "apply.remark": a
        });
    },
    storeIn: function(t) {
        console.log(t.detail.value);
        var a = t.detail.value;
        this.setData({
            "apply.storeIntroduce": a
        });
    },
    Chooseinp: function(t) {
        var a = t.detail;
        this.setData({
            agreementChoose: a
        });
    },
    removeImg: function(t) {
        var a = t.currentTarget.dataset.index, e = this.data.apply.aptitute, s = this.data.fileList2;
        e.splice(a, 1), s.splice(a, 1), this.setData({
            "apply.aptitute": e,
            fileList2: s
        });
    },
    setApplyData: function() {
        if (console.log(this.data.apply), !a._isTextEmpty(this.data.apply.username) || this.data.apply_switch) if (!a._isTextEmpty(this.data.apply.password) || this.data.apply_switch) if (3 == this.data.msgText || 1 != this.data.applyOptionInfo.safe) if (a._isTextEmpty(this.data.apply.realname)) wx.showToast({
            icon: "none",
            title: "请填写真实姓名",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.mobile)) wx.showToast({
            icon: "none",
            title: "请填写手机号码",
            duration: 1500
        }); else if (a._isMoblie(this.data.apply.mobile)) wx.showToast({
            icon: "none",
            title: "请输入正确的手机号",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.deliver_name)) wx.showToast({
            icon: "none",
            title: "请填写提货点名称",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.province_id) || a._isTextEmpty(this.data.apply.city_id) || a._isTextEmpty(this.data.apply.district_id)) wx.showToast({
            icon: "none",
            title: "请选择省市区",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.street_id)) wx.showToast({
            icon: "none",
            title: "请选择街道",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.address)) wx.showToast({
            icon: "none",
            title: "请填写详细地址",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.lng) || a._isTextEmpty(this.data.apply.lat)) wx.showToast({
            icon: "none",
            title: "经纬度不能为空",
            duration: 1500
        }); else if (a._isTextEmpty(this.data.apply.business_hours_start) || a._isTextEmpty(this.data.apply.business_hours_end)) wx.showToast({
            icon: "none",
            title: "营业开始时间活营业结束时间不能为空",
            duration: 1500
        }); else if (this.data.applyOptionInfo.is_license && a._isTextEmpty(this.data.apply.aptitute)) wx.showToast({
            icon: "none",
            title: "请上传营业执照",
            duration: 1500
        }); else if (this.data.applyOptionInfo.is_photo && a._isTextEmpty(this.data.apply.thumb)) wx.showToast({
            icon: "none",
            title: "请上传".concat(this.data.applyOptionInfo.name, "图片"),
            duration: 1500
        }); else if (this.data.agreementChoose) {
            var t, e = this, s = {
                apply: this.data.apply
            };
            t = a.getNetAddresss("plugin.package-deliver.frontend.apply.store"), a._postNetWork({
                url: t,
                showToastIn: !1,
                data: s,
                success: function(t) {
                    var a = t.data;
                    if (1 == a.result) {
                        try {
                            wx.removeStorageSync("ztd_temporary");
                        } catch (t) {}
                        wx.showToast({
                            title: a.msg,
                            icon: "none",
                            duration: 1500,
                            success: function() {
                                setTimeout(function() {
                                    e.goHome();
                                }, 1500);
                            }
                        });
                    } else wx.showToast({
                        icon: "none",
                        title: a.msg,
                        duration: 1500
                    });
                },
                fail: function(t) {}
            });
        } else wx.showToast({
            icon: "none",
            title: "请同意申请协议",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请正确填写密码",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请填写密码",
            duration: 1500
        }); else wx.showToast({
            icon: "none",
            title: "请填写账号",
            duration: 1500
        });
    },
    goHome: function() {
        wx.reLaunch({
            url: "/packageG/index/index"
        });
    },
    levelShowbtn: function() {
        this.setData({
            levelShow: !0
        });
    },
    levelShowLeft: function() {
        this.setData({
            levelShow: !1
        });
    },
    chooseStarLevel: function(t) {
        var a = t.currentTarget.dataset.item;
        this.setData({
            "apply.starRated": a.value,
            levelShow: !1,
            levelName: a.name
        });
    }
});